package com.example.redisdemon.service;

import com.example.redisdemon.entity.Book;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

/**
 * @ClassName BookService
 * @Description TODO
 * @Author leejiliang
 * @DateTime 2020/5/1 10:45 PM
 * @Version 1.0
 */
@Service
public class BookService {
	private final static Logger logger = LoggerFactory.getLogger(BookService.class);

	@CachePut(value = "book", key = "#book.id")
	public void saveBook(Book book) {
		logger.info("保存了book");
	}

	@Cacheable(value = "book", key = "#id")
	public Book getBook(Long id) {
		logger.info("我找到了...");
		return new Book();
	}

	@CacheEvict(value = "book", key = "#id")
	public void deleteBook(Long id) {
		logger.info("删除了{}", id);
	}
}
